#
#  Ships.py
#  TwoHand
#
#  Created by Pete Lord on 16/12/2008.
#  Copyright (c) 2008 __MyCompanyName__. All rights reserved.
#
import pygame, math, Weapons

class Ship():
    def __init__(self, entities, screen, x, y, rotation):
        self.entities = entities # allows the ship to add bullets to the level.
        self.screen = screen
        self.x = x
        self.y = y
        self.rotation = 0
        self.speed = 2 # arbitrary value. Should be redefined. 
        
    def moveLeft(self):
        self.x -= self.speed
        
    def moveRight(self):
        self.x += self.speed
        
    def moveDown(self):
        self.y += self.speed

    def moveUp(self):
        self.y -= self.speed
        
    def getXY(self):
        return (self.x, self.y)
        
    def offsetPoints(self, list):
        # calculate points for drawing purposes. So that the ship gets drawn at the right location, rather than around 0,0
        returnList = []
        for point in list:
            returnList.append([(point[0] + self.x), (point[1] + self.y)])
        return returnList
        
    def rotatePoints(self, list, amount):
        pass # to be done.
        
    def twistPoints(self, list, amount):
        returnList = []
        for point in list:
            returnList.append([(point[0] / (point[0] * 0.25)),(point[1] / (point[1] * 0.25))])
        return returnList
    
    def draw(self):
        self.bodyPoints_OFFSET = self.offsetPoints(self.bodyPoints)
        self.decorationPoints_OFFSET = self.offsetPoints(self.decorationPoints)
        
        pygame.draw.polygon(self.screen, (0, 0, 0), self.bodyPoints_OFFSET, 0)
        pygame.draw.aalines(self.screen, (255, 255, 255), True, self.bodyPoints_OFFSET) # body
        
        pygame.draw.polygon(self.screen, (0, 0, 0), self.decorationPoints_OFFSET, 0)
        pygame.draw.aalines(self.screen, (255, 255, 255), True, self.decorationPoints_OFFSET) # decoration
        
class Player(Ship):
    def __init__(self, entities, screen, x, y, rotation):
        Ship.__init__(self, entities, screen, x, y, rotation)
        # This game uses a different rotation method to peteship.
        # A standard points list is defined at the beginning, with 0,0 as the centre.
        # You can then rotate this as nessecary. The ship is draw with x,y as it's offset.
        # So basically a point is just xy and doesn't depend on a radius. Ace.
        # Radiace.
        # Tuples for points, list overall for passing to pygame draw.
        # Ship designer coming soon!
        
        # Player ship is different as it has a cockpit, body and weapons.
        
        # Y IS INVERTED !!!
        
        self.cockpitPoints = [(-2, -40), (2, -40), (5, -24), (2, -20), (-2, -20), (-5, -24)]
        self.bodyPoints = [(0, -35), (10, -26), (40, 20),\
                           (20, 20), (20, 10), (10, 10), (10, 20),\
                           (0, 30),\
                           (-10, 20), (-10, 10), (-20, 10), (-20, 20),\
                           (-40, 20), (-10, -26)] # meh it's a body.
        # wepaons draw themselves and manage their own points. That's important to them like. For interpolation.
        self.weaponA = Weapons.TestGun(self.entities, self.screen, -30, 10, self, False) # testgun, away!
        self.weaponB = Weapons.TestGun(self.entities, self.screen, 30, 10, self, False) # testgun, away!
        
    def poll(self):
        self.weaponA.poll()
        self.weaponB.poll()
        
    def draw(self):
        self.weaponA.draw() # draw te guns!
        self.weaponB.draw()
        # currently filled in. - black background to the ship.
        # offset points.
        self.bodyPoints_OFFSET = self.offsetPoints(self.bodyPoints)
        self.cockpitPoints_OFFSET = self.offsetPoints(self.cockpitPoints)
        
        # draw.
        pygame.draw.polygon(self.screen, (0, 0, 0), self.bodyPoints_OFFSET, 0)
        pygame.draw.aalines(self.screen, (255, 255, 255), True, self.bodyPoints_OFFSET) # body
        
        pygame.draw.polygon(self.screen, (0, 0, 0), self.cockpitPoints_OFFSET, 0)        
        pygame.draw.aalines(self.screen, (255, 255, 255), True, self.cockpitPoints_OFFSET) # cockpit
        
        
        
        